import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.PriorityBlockingQueue;

class MyThreadPool1{
    MyThreadPool1(int n) {
        for (int i = 0; i <n ; i++) {
            Thread thread=new Thread(()->{
                while(true){

                    try {
                       Runnable runnable = queue.take();
                        runnable.run();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }

                }
            });
            thread.start();
        }
    }


    private BlockingDeque<Runnable> queue=new LinkedBlockingDeque<>();

    //注册任务给
    public void submit(Runnable runnable){
        try {
            queue.put(runnable);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}



public class ThreadDemo2 {
    public static void main(String[] args) {
        MyThreadPool1 myThreadPool=new MyThreadPool1(10);
        for (int i = 0; i < 10000; i++) {
            int n=i;
            myThreadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("hello"+n);
                }
            });
        }
    }
}
